<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title><script type="text/javascript">
		let colors=[]
		function init(){
			let xhr=new XMLHttpRequest
			xhr.open("GET","color.xml",true)
			xhr.send()
			xhr.onreadystatechange=function(){
				if(xhr.readyState==4&&xhr.status==200){
					let data=xhr.responseXML
					colors = data.querySelectorAll("color")//找到sus.xml中的
					let select = document.querySelector("select")
					for (var i = 0; i < colors.length; i++) { 
						select.options[i]=new Option(colors[i].querySelector("name").innerHTML)
				}
				let c = colors[0].querySelector("value").innerHTML
				document.body.setAttribute("style","background-color:"+c+"")//字符串拼接
			}
		}	
		}
		</script>
	</head>
	<body onload="init()">
		请选择网页背景色<select></select>
		<script type="text/javascript">
			let select = document.querySelector("select")
			select.addEventListener("change",function(){
				let index = select.selectedIndex//下拉列表中被选中选项的索引
				let c = colors[index].querySelector("value").innerHTML
				document.body.setAttribute("style","background-color:"+c+"")//字符串拼接
				
				
			})
		</script>
	</body>

</html>
